<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="140px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="转让人手机号">
              <el-input v-model="params.transferorPhone" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="被转让人手机号">
              <el-input v-model="params.transfereePhone" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分公司">
              <el-select placeholder="请选择" clearable v-model="params.companyId">
                <el-option
                  v-for="item in officeOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="search">查询</el-button>
              <router-link to="addassign">
                <el-button style="margin-left:60px" type="primary">添加转让</el-button>
              </router-link>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-table :data="tableData" class="tableData" style="width: 100%">
      <el-table-column type="index" label="序列" align="center" :index="table_index" width="50"></el-table-column>
      <el-table-column prop="transferorPhone" label="转让人手机号">
        <template slot-scope="scope">
          <div>{{scope.row.transferorPhone | phonereg }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="transferorName" label="转让人姓名" />
      <el-table-column prop="transfereePhone" label="被转让人手机号">
        <template slot-scope="scope">
          <div>{{scope.row.transfereePhone | phonereg }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="transfereeName" label="被转让人姓名" />
      <el-table-column prop="roleName" label="级别" />
      <el-table-column prop="type" label="账号类型" />
      <el-table-column prop="transTime" label="转让时间" />
      <el-table-column prop="amount" label="签约金额" />
      <el-table-column prop="companyName" label="分公司" />
      <el-table-column prop="remark" label="转让说明" />
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="params.pageNum"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="params.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import { companyList } from "@/api/branchOfficeDropDown";
import assignment from "@/api/assignment";
export default {
  data() {
    return {
      params: {
        transferorPhone: "",
        transfereePhone: "",

        pageNum: 1,
        pageSize: 10
      },
      officeOption: [],
      tableData: [],
      total: 0
    };
  },
  mounted() {
    this.getCompanyList();
    this.getList();
  },
  methods: {
    search() {
      this.params.current = 1;
      if (!this.params.companyId) {
        this.params.companyId = null;
      }
      this.getList();
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.getList();
    },
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    },
    async getList() {
      let res = await assignment.list(this.params);
      console.log(res);
      if (res.data.code == 0) {
        this.tableData = res.data.data.list;
        this.total = res.data.data.count;
      }
    },
    //获取分公司列表
    getCompanyList() {
      companyList({ types: [0] })
        .then(res => {
          let resData = res.data.data;
          let newData = [];
          resData.forEach(e => {
            newData.push({
              value: e.id,
              label: e.name
            });
          });
          this.officeOption = newData;
        })
        .catch(error => {
          this.$message.error(error);
        });
    }
  }
};
</script>
